<?php
/**
* Implements a "book", which is something with an index that is part of an html page.
*<p>Derived from Box...</p>
*@package Page
*@author Willy Gardiol <willy@gardiol.org>
*@version 1.0
*/
abstract class PageBook extends Box
{
	public function __construct( $title, $edit_type = "popup" )
	{
		parent::__construct( $title, $edit_type );
		$this->SetStorage( array("page_data" => array() ) );
		Core::RegisterGetVar("_p");
	}

	public function SetPageData( $id, $data )
	{
		$page_data = $this->Get("page_data");
		if ( !is_array($page_data) )
			$page_data = array();
		$page_data[$id] = $data;
		$this->Set("page_data", $page_data );
		$this->SetModified(true);
	}
	public function AddPage( $id, $data )
	{
		$this->SetChild( $id, $id );
		$this->SetPageData( $id, $data );
	}

	public function RemovePage( $id )
	{
		$this->RemoveChild( $id );
		$page_titles = $this->Get("page_data");
		unset( $page_titles[$id] );
		$this->Set("page_data", $page_titles );
		$this->SetModified(true);
	}

	public function ListPages()
	{
		$page_data = $this->Get("page_data");
		foreach ( $page_data as $page_id => $data )
		{
			$page = AtomCache::GetAtomData( $page_id );
			if ( $page )
				$page_data[ $page_id ]["title"] = $page->GetTitle();
			else
			{
				$this->RemovePage( $page_id );
				unset( $page_data[ $page_id ] );
			}
		}
#		var_dump( $page_data );
		return $page_data;
	}

	public function GetMyUrl( $page_id = "page_no_specified_" )
	{
		$page_id =  ($page_id == "page_no_specified_") ? $page_id : Core::GetVar("_p", false, "string");
		return new Url( array("_s" => $this->GetId(),
						"_p" => $page_id ) );
	}

	final protected function GenerateHtml()
	{
		$page = Core::GetVar("_p", false, "string");
		return "PAGE BOOK DA RISCRIVERE".$this->SheetGenerateHtml( $page );
	}

	protected function SheetGenerateHtml( $page )
	{
		return I18N("Please override");
	}
}
?>